package com.mc.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mc.model.Path;
import com.mc.model.ScienceDirection;
import com.mc.model.ScienceDirectionWithBLOBs;
import com.mc.model.ScienceTeacher;
import com.mc.model.newsandbulletin;
import com.mc.service.IScienceDirectionService;
import com.mc.service.IScienceTeacherService;
import com.mc.service.NewsandbulletService;
import com.mc.utils.PathUtil;
import com.mc.utils.StringUtil;

@Controller
@RequestMapping("/scienceyj")
public class ScienceYJAction {

	@Autowired private NewsandbulletService newsandbulletService;
	@Autowired private IScienceDirectionService directionService;
	@Autowired private IScienceTeacherService scienceTeacherService;
	private Path path = null;
	/**
	 * 
	 * @param modelMap
	 * @return 科研首页
	 */
	
	@RequestMapping("/scienceyjindex")
	public String bkpy(ModelMap modelMap)
	{
		List<newsandbulletin> nb =  newsandbulletService.selectkynews(0, 5);
		StringUtil.getInstace().replaceTitle(nb);
		modelMap.addAttribute("nb", nb);
		List<newsandbulletin> pnewses=newsandbulletService.selectnbbytype("bulletin", 32,0, 3);
		modelMap.addAttribute("pnewses", pnewses);
		List<ScienceDirection> directions = directionService.selectalldirections();
		modelMap.addAttribute("directions", directions);
		path = PathUtil.setPathParams(new String[]{"PackageName:ScienceYJ","ViewName:kxyj","ViewTitle:科学研究","smenu:ScienceYJ","mmenu:ScienceYJindex"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @param id 科学研究页面id
	 * @return 简介
	 */
	@RequestMapping("/detail/{id}")
	public String detail(ModelMap modelMap,@PathVariable("id")int id){
		
		ScienceDirectionWithBLOBs directionWithBLOBs = directionService.selectByPrimaryKey(id);
		modelMap.addAttribute("directionWithBLOBs", directionWithBLOBs);
		List<ScienceTeacher> sciencefzTeacher = scienceTeacherService.selectbydirectionfzid(id);
		modelMap.addAttribute("sciencefzTeacher", sciencefzTeacher);
		
		List<ScienceTeacher> scienceTeacher = scienceTeacherService.selectbydirectionid(id);
		modelMap.addAttribute("scienceTeacher", scienceTeacher);
		path = PathUtil.setPathParams(new String[]{"" +
				"PackageName:ScienceYJ","ViewName:detail",
				"ViewTitle:科学研究--"+directionWithBLOBs.getDirectionName(),"smenu:ScienceYJ","mmenu:other"});				
		return PathUtil.returnStr(path, modelMap);
	}
}
